import request from '@/utils/request'
import { downloadFile } from '@/utils'

export function add(data) {
  return request({
    url: '/oauth/dict/add',
    method: 'post',
    data
  })
}

export function del(id) {
  return request({
    url: '/oauth/dict/delete',
    method: 'post',
    data: [id]
  })
}

export function edit(data) {
  return request({
    url: '/oauth/dict/update',
    method: 'post',
    data
  })
}

export function get(id) {
  return request({
    url: '/oauth/dict/get',
    method: 'get',
    params: { id }
  })
}

export function getDictDetail(clazzField) {
  return request({
    url: '/oauth/dict/getDetail',
    method: 'get',
    params: { clazzField }
  })
}
export function expCSV(params) {
  return request({
    url: '/oauth/dict/export',
    method: 'get',
    responseType: 'blob',
    params
  }).then((data) => {
    downloadFile(data, 'dict', 'csv')
  })
}
